package com.yhos.platform.oopston.core.base;


import com.yhos.platform.oopston.core.constant.OperatorConstant;

import java.util.List;

public class Result {

    /**
     * 返回操作成功,不含具体业务数据
     * @return
     */
    public static Response SUCCESS() {
        Response response = new Response();
        response.setSuccess(OperatorConstant.RETURN_SUCCESS);
        response.setMsg(OperatorConstant.OPERATOR_SUCCESS);
        return response;
    }

    /**
     * 返回操作成功，包含具体业务数据
     * @param val
     * @param <T>
     * @return
     */
    public static <T> Response<T> SUCCESS(T val) {
        Response<T> response = new Response<>();
        response.setSuccess(OperatorConstant.RETURN_SUCCESS);
        response.setMsg(OperatorConstant.OPERATOR_SUCCESS);
        response.setVal(val);
        return response;
    }

    /**
     * 返回操作失败
     * @return
     */
    public static Response FAILED() {
        Response response = new Response();
        response.setSuccess(OperatorConstant.RETURN_FAILURE);
        response.setMsg(OperatorConstant.OPERATOR_FAILURE);
        return response;
    }

    /**
     * 返回操作失败，指定具体操作失败提示
     * @param message
     * @return
     */
    public static Response FAILED(String message) {
        Response response = new Response();
        response.setSuccess(OperatorConstant.RETURN_FAILURE);
        response.setMsg(message);
        return response;
    }

    /**
     * 返回操作失败，指定错误code和message
     * @param ret
     * @param message
     * @return
     */
    public static Response FAILED(String ret, String message) {
        Response response = new Response();
        response.setSuccess(OperatorConstant.RETURN_FAILURE);
        response.setRet(ret);
        response.setMsg(message);
        return response;
    }

    /**
     * 返回分页信息,包含具体业务数据
     * @param val
     * @param <T>
     * @return
     */
    public static <T> PageResponse<List<T>> PAGE(Page<T> val) {
        PageResponse<List<T>> response = new PageResponse<>();
        response.setSuccess(OperatorConstant.RETURN_SUCCESS);
        response.setMsg(OperatorConstant.OPERATOR_SUCCESS);
        response.setPageInfo(new PageInfo(val));
        response.setVal(val.getRecords());
        return response;
    }

    /**
     * 返回分页错误信息，不含具体业务数据（熔断的时候使用）
     * @param <T>
     * @return
     */
    public static <T> PageResponse<List<T>> PAGE_FAILED() {
        PageResponse<List<T>> response = new PageResponse<>();
        response.setSuccess(OperatorConstant.RETURN_FAILURE);
        response.setMsg(OperatorConstant.OPERATOR_FAILURE);
        return response;
    }

    /**
     * 返回分页错误信息，指定错误message
     * @param message
     * @param <T>
     * @return
     */
    public static <T> PageResponse<List<T>> PAGE_FAILED(String message) {
        PageResponse<List<T>> response = new PageResponse<>();
        response.setSuccess(OperatorConstant.RETURN_FAILURE);
        response.setMsg(message);
        return response;
    }

    /**
     * 返回分页错误信息，指定错误Code和message
     * @param ret
     * @param message
     * @param <T>
     * @return
     */
    public static <T> PageResponse<List<T>> PAGE_FAILED(String ret, String message) {
        PageResponse<List<T>> response = new PageResponse<>();
        response.setSuccess(OperatorConstant.RETURN_FAILURE);
        response.setRet(ret);
        response.setMsg(message);
        return response;
    }

}
